package com.irdstudio.bhcredit.core.assembly.plugin.common;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 数据表操作类-[表名: 01.平台子系统基础信息表(s_subs_info)]
 * 通过JDBC实现基本的数据表操作(CRUD) 
 * @author 代码自动生成
 * @version 1.0
 * @date 2013-10-25
 */
public class SSubsInfoDao {

	private static final Logger logger = LoggerFactory.getLogger(SSubsInfoDao.class);
	/* 连接对象 */
	Connection conn = null;	

	public SSubsInfoDao(Connection conn){
		this.conn = conn;
	}

	/**
	 * 根据主键查询单条记录
	 * @param 
	 * @return
	 * @throws SQLException
	 */
	public SSubsInfo querySSubsInfoWithKeys(String subsCode)
			throws SQLException {
		SSubsInfo dc = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			ps = conn
					.prepareStatement("SELECT * FROM s_subs_info WHERE subs_code=?");
			ps.setString(1,subsCode);
			rs = ps.executeQuery();
			if (rs.next()) {
				dc = new SSubsInfo();
				dc.setSubsCode(rs.getString("subs_code"));
				dc.setSubsName(rs.getString("subs_name"));
				dc.setSubsDataDate(rs.getString("subs_data_date"));
				dc.setSubsLastDataDate(rs.getString("subs_last_data_date"));
				dc.setSubsLoadDate(rs.getString("subs_load_date"));
				dc.setSubsBatDate(rs.getString("subs_bat_date"));
				dc.setBatchIdPrefix(rs.getString("batch_id_prefix"));
				dc.setRsvDate(rs.getString("rsv_date"));
				dc.setRsvState(rs.getString("rsv_state"));
			}
		} catch (SQLException e) {
			throw new SQLException("querySSubsInfoWithKeys is Wrong!"
					+ e.getMessage());
		} finally {
			close(rs, null, ps);
		}
		return dc;
	}

	/**
	 * 根据查询条件查询多条或单条记录
	 * @param szCondition 
	 * @return
	 * @throws SQLException
	 */
//	public List<SSubsInfo> querySSubsInfoWithCond(String szCondition,String szOrderBy)
//			throws SQLException {
//		List<SSubsInfo> dcList = new ArrayList<SSubsInfo>();
//		PreparedStatement ps = null;
//		ResultSet rs = null;
//		try {
//			ps = conn.prepareStatement("SELECT * FROM s_subs_info "
//					+ szCondition + " " + szOrderBy);
//			rs = ps.executeQuery();
//			while (rs.next()) {
//				SSubsInfo dc = new SSubsInfo();
//				dc.setSubsCode(rs.getString("subs_code"));
//				dc.setSubsName(rs.getString("subs_name"));
//				dc.setSubsDataDate(rs.getString("subs_data_date"));
//				dc.setSubsLastDataDate(rs.getString("subs_last_data_date"));
//				dc.setSubsLoadDate(rs.getString("subs_load_date"));
//				dc.setSubsBatDate(rs.getString("subs_bat_date"));
//				dc.setBatchIdPrefix(rs.getString("batch_id_prefix"));
//				dc.setRsvDate(rs.getString("rsv_date"));
//				dc.setRsvState(rs.getString("rsv_state"));
//				dcList.add(dc);
//			}
//		} catch (SQLException e) {
//			throw new SQLException("querySSubsInfoWithCond is Wrong!"
//					+ e.getMessage());
//		} finally {
//			close(rs, null, ps);
//		}
//		return dcList;
//	}

	/**
	 * 关闭资源
	 * @param theRs
	 * @param theStmt
	 * @param thePs
	 */
	protected void close(ResultSet theRs, Statement theStmt,
			PreparedStatement thePs) {
		try {
			if (theRs != null)
				theRs.close();
			if (theStmt != null)
				theStmt.close();
			if (thePs != null)
				thePs.close();
		} catch (SQLException e) {
			logger.error(e.getMessage());
		}
	}

}
